
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module call.session
* @author: Hjava
* @description: VOIP语音模块协议定义
* @since: 2018-07-21 15:39:46
*/
var call_constant_1 = __webpack_require__(/*! _call/call.constant */ "./src/core/call/call.constant.ts");
var deviceInfo_1 = __webpack_require__(/*! _util/deviceInfo */ "./src/core/utils/deviceInfo.ts");
var timer_1 = __webpack_require__(/*! _util/timer */ "./src/core/utils/timer.ts");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var bufferType_1 = __webpack_require__(/*! _util/bufferType */ "./src/core/utils/bufferType.ts");
var uuid_1 = __webpack_require__(/*! _util/uuid */ "./src/core/utils/uuid.ts");
var CallSession = {};
/**
 * 创建会议室Session
 */
CallSession.PCallCreate = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_CREATE,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_CREATE;
        this.uid = 0;
        this.callUuid = uuid_1.default.next();
        this.deviceType = deviceInfo_1.default.deviceType;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG); //客户端消息ID
        this.push(this.callUuid);
        this.push(this.deviceType, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.callUuid = this.popString();
        this.deviceType = this.popByte();
    }
});
/**
 * 创建会议室成功返回协议，告诉客户端sid (服务器的Ack)
 */
CallSession.PCallCreateAck = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_CREATE_ACK,
    marshall: function () {
        this.push(this.rescode, bufferType_1.default.INT);
        this.push(this.callUuid, bufferType_1.default.STRING);
        this.push(this.sid, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        this.rescode = this.popInt();
        this.callUuid = this.popString();
        this.sid = this.popString();
    }
});
/**
 * 客户端测试语音通话session是否有效，在收到邀请时候发送。
 */
CallSession.PCallDetect = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_DETECT,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_DETECT;
        this.uid = '';
        this.sid = '';
        this.deviceType = deviceInfo_1.default.deviceType;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.sid, bufferType_1.default.STRING);
        this.push(this.deviceType, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.sid = this.popString();
        this.deviceType = this.popByte();
    }
});
/**
 * 服务器对PCallDetect回复测试结果。
 * 参考ProtoRes:
 * RES_SUCCESS : 成功
 * RES_FAIL：失败
 */
CallSession.PCallDetectAck = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_DETECT_ACK,
    init: function () {
        this.sid = '';
        this.rescode = 0;
    },
    marshall: function () {
        this.push(this.sid, bufferType_1.default.STRING);
        this.push(this.rescode, bufferType_1.default.INT);
    },
    unmarshall: function () {
        this.sid = this.popString();
        this.rescode = this.popInt();
    }
});
/**
 * 发起语音会话
 */
CallSession.PCallInvite = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_INVITE,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_INVITE;
        this.uid = '';
        this.peerUid = '';
        this.cts = timer_1.default.get();
        this.sid = '';
        this.name = '';
        this.peerAppid = 0;
        this.deviceType = deviceInfo_1.default.deviceType;
        this.callType = 0;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.peerUid, bufferType_1.default.LONG);
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.sid);
        this.push(this.name);
        this.push(this.peerAppid, bufferType_1.default.SHORT);
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.callType, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.peerUid = this.popLong().value();
        this.cts = this.popLong().value();
        this.sid = this.popString();
        this.name = this.popString();
        this.peerAppid = this.popShort();
        this.deviceType = this.popByte();
        this.callType = this.popByte();
    }
});
CallSession.PCallInvite2 = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_INVITE2,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_INVITE2;
        this.uid = '';
        this.gid = '';
        this.cts = timer_1.default.get();
        this.sid = '';
        this.name = '';
        this.invitees = []; // [{uid, ai}]
        this.deviceType = deviceInfo_1.default.deviceType;
        this.callType = 0;
        this.meetingType = 0;
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.gid = this.popLong().value();
        this.cts = this.popLong().value();
        this.sid = this.popString();
        this.name = this.popString();
        this.invitees = this.popUItems();
        this.deviceType = this.popByte();
        this.callType = this.popByte();
        this.meetingType = this.popByte();
    }
});
CallSession.PCallHalfwayInvite = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_HALFWAY_INVITE,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_HALFWAY_INVITE;
        this.uid = '';
        this.gid = '';
        this.cts = timer_1.default.get();
        this.sid = '';
        this.name = '';
        this.invitees = [];
        this.deviceType = deviceInfo_1.default.deviceType;
        this.callType = 0;
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.gid = this.popLong().value();
        this.cts = this.popLong().value();
        this.sid = this.popString();
        this.name = this.popString();
        this.invitees = this.popUItems();
        this.deviceType = this.popByte();
        this.callType = this.popByte();
    }
});
/**
 * 服务器收到PCallInvite给客户端回ack。
 */
CallSession.PCallInviteAck = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_INVITE_ACK,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_INVITE_ACK;
        this.sid = '';
        this.rescode = 0;
    },
    marshall: function () {
        this.push(this.sid);
        this.push(this.rescode, bufferType_1.default.INT);
    },
    unmarshall: function () {
        this.sid = this.popString();
        this.rescode = this.popInt();
    }
});
/**
 * 客户端被叫收到PCallInvite，对应操作的回复协议
 */
CallSession.PCallInivteResponse = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_INVITE_RESPONSE,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_INVITE_RESPONSE;
        this.uid = 0;
        this.sid = 0;
        this.action = '';
        this.deviceType = deviceInfo_1.default.deviceType;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.sid);
        this.push(this.action, bufferType_1.default.BYTE);
        this.push(this.deviceType, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.sid = this.popString();
        this.action = this.popByte();
        this.deviceType = this.popByte();
    }
});
/**
 * 服务器收到PCallInivteResponse回复客户端ack
 * 参考ProtoRes:
 * RES_SUCCESS : 成功
 * RES_FAIL：失败
 */
CallSession.PCallInivteResponseAck = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_INVITE_RESPONSE_ACK,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_INVITE_RESPONSE_ACK;
        this.sid = '';
        this.rescode = 0;
        this.action = 0;
    },
    marshall: function () {
        this.push(this.sid, bufferType_1.default.STRING);
        this.push(this.rescode, bufferType_1.default.INT);
        this.push(this.action, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.sid = this.popString();
        this.rescode = this.popInt();
        this.action = this.popByte();
    }
});
/**
 * 断网重连，重新加入通话。
 */
CallSession.PCallJoin = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_MEMBER_JOIN,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_MEMBER_JOIN;
        this.uid = '';
        this.sid = '';
        this.deviceType = deviceInfo_1.default.deviceType;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.sid, bufferType_1.default.STRING);
        this.push(this.deviceType, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.sid = this.popString();
        this.deviceType = this.popByte();
    }
});
/**
 * 服务器对PCallJoin的应答。
 * 参考ProtoRes:
 * RES_SUCCESS : 成功
 * RES_FAIL：失败
 */
CallSession.PCallJoinAck = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_MEMBER_JOIN_ACK,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_MEMBER_JOIN_ACK;
        this.sid = '';
        this.rescode = 0;
    },
    marshall: function () {
        this.push(this.sid, bufferType_1.default.STRING);
        this.push(this.rescode, bufferType_1.default.INT);
    },
    unmarshall: function () {
        this.sid = this.popString();
        this.rescode = this.popInt();
    }
});
/**
 * 通话过程中挂断会话
 */
CallSession.PCallLeave = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_LEAVE,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_LEAVE;
        this.uid = '';
        this.sid = '';
        this.deviceType = deviceInfo_1.default.deviceType;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.sid, bufferType_1.default.STRING);
        this.push(this.deviceType, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.sid = this.popString();
        this.deviceType = this.popByte();
    }
});
/**
 * 通知通话内成员变化
 */
CallSession.PCallMemberChange = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_MEMBER_CHANGE,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_MEMBER_CHANGE;
        this.deleteUids = [];
        this.addUids = [];
        this.currentUids = [];
        this.sid = '';
        this.leaveReason = {};
    },
    // marshall:function() {
    //     this.push(this.deleteUids, bt.ARRAY_LONG);
    //     this.push(this.addUids, bt.ARRAY_LONG);
    //     this.push(this.currentUids, bt.ARRAY_LONG);
    //     this.push(this.sid, bt.STRING);
    //     this.push(this.leaveReason,);
    // },
    unmarshall: function () {
        this.deleteUids = this._popArrayLong();
        this.addUids = this._popArrayLong();
        this.currentUids = this._popArrayLong();
        this.sid = this.popString();
        this.leaveReason = this.popMapOfLongAndByte();
    }
});
/**
 * 服务器收到PCallInivteResponse，下发notify给客户端，通知invite结果。例如：
 * A呼叫B（手机端和pc同时在线），B手机端回了PCallInivteResponse，服务器通知A和B pc端 response的结果。
 */
CallSession.PCallNotify = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_NOTIFY,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_NOTIFY;
        this.uid = '';
        this.sid = '';
        this.action = 0;
        this.deviceType = deviceInfo_1.default.deviceType;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.sid, bufferType_1.default.STRING);
        this.push(this.action, bufferType_1.default.BYTE);
        this.push(this.deviceType, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.sid = this.popString();
        this.action = this.popByte();
        this.deviceType = this.popByte();
    }
});
/**
 * 通话心跳包
 */
CallSession.PCallPing = protocol_1.default.Request.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_PING,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_PING;
        this.uid = '';
        this.cts = timer_1.default.get();
        this.deviceType = deviceInfo_1.default.deviceType;
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.deviceType, bufferType_1.default.BYTE);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.cts = this.popLong().value();
        this.deviceType = this.popByte();
    }
});
/**
 * 服务器回的心跳包
 */
CallSession.PCallPingAck = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_PING_ACK,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_PING_ACK;
        this.cts = 0;
        this.sts = 0;
    },
    marshall: function () {
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.sts, bufferType_1.default.LONG);
    },
    unmarshall: function () {
        this.cts = this.popLong().value();
        this.sts = this.popLong().value();
    }
});
/**
 * 语音通话质量
 * public static class NetQuality {
 *      public static byte Q_SIGNAL_NORMAL = 0;//和信令ping正常
 *      public static byte Q_SIGNAL_TIMEOUT = 10; //和信令ping超时
 * }
 * 当信令服务检查到超时，会主动通知通话成员
 * 其它情况转发客户端通话质量通知
 */
CallSession.PCallQualityNotify = protocol_1.default.Response.extend({
    category: 'Call',
    uri: call_constant_1.default.Call.URI_CALL_QUALITY_NOTIFY,
    init: function () {
        this.uri = call_constant_1.default.Call.URI_CALL_INVITE_ACK;
        this.uid = '';
        this.deviceType = deviceInfo_1.default.deviceType;
        this.quality = 0;
        this.sid = '';
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.quality, bufferType_1.default.BYTE);
        this.push(this.sid, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.deviceType = this.popByte();
        this.quality = this.popByte();
        this.sid = this.popString();
    }
});
exports.default = CallSession;


//# sourceURL=webpack://MTDX/./src/core/call/call.session.ts?